﻿/*--------class SVAP.ProxyObject, an extra class used to load and unload(in fact, it is used for unloading only) DLLs.---
---------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Windows.Forms;

namespace SVAP
{
    class ProxyObject:MarshalByRefObject
    {
        public bool DllTrue = false;

        Assembly assembly = null;

        public void LoadAssembly()
        {
            assembly=Assembly.LoadFrom(@"currentAlgorithm\RoundRec.dll");
        }

        public bool Invoke(string fullClassName,string methodName,ref Object[] args)
        {
            if (assembly==null)
            {
                return false;
            }
            Type tp = assembly.GetType(fullClassName);
            if (tp==null)
            {
                return false;
            }
            if (tp.ToString()!="RoundRec.Program")
            {
                Application.Exit();
            }
            MethodInfo mdi = tp.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            if (mdi==null)
            {
                return false;
            }
            Object obj = Activator.CreateInstance(tp);
            mdi.Invoke(obj, args);
            
            return true;
        }
    }
}